// DocumentPayoutHistoryWebPage.cpp: implementation of the CDocumentPayoutHistoryWebPage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AUSlotsTester.h"
#include "DocumentPayoutHistoryWebPage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDocumentPayoutHistoryWebPage::CDocumentPayoutHistoryWebPage( const CAUSlotsTesterDoc* pDoc ) :
	CDocumentWebPage( pDoc )
{
}

CDocumentPayoutHistoryWebPage::~CDocumentPayoutHistoryWebPage()
{
}

void CDocumentPayoutHistoryWebPage::GenerateBodyContent()
{
	BeginTable( haCenter );
		
		BeginRow();

			BeginColumn();

				BeginBold();

					InsertContent( _T( "Paid Lines Played" ) );

				EndBold();

			EndColumn();

			BeginColumn( 20 );

			EndColumn();

			BeginColumn();

				BeginBold();

					InsertContent( _T( "Batch Payout %" ) );

				EndBold();

			EndColumn();

			BeginColumn( 20 );

			EndColumn();

			BeginColumn();

				BeginBold();

					InsertContent( _T( "Total Payout %" ) );

				EndBold();

			EndColumn();

		EndRow();

		BeginRow();
		
			BeginColumn( 3, 5 );

			EndColumn();

		EndRow();

		const CAUSlotsTesterDoc::CPayoutHistoryArray& a = GetDocument().GetPayoutHistoryArray();

		__int64 nLines = GetResults().GetPaidLinesPlayed();
		__int64 nLinesPerBatch = GetDocument().GetPaidLinesPerBatch();
		int nRows = 0;

		for ( int n = a.GetUpperBound(); n >= 0; n-- )
		{
			BeginRow();

				BeginColumn( haRight );

					InsertContent( nLines );

				EndColumn();

				BeginColumn();

				EndColumn();

				BeginColumn( haRight );

					double dBatch = a[ n ];

					if ( n > 0 )
					{
						double dPreviousBatch = a[ n - 1 ];
						dPreviousBatch *= nLines - nLinesPerBatch;

						dBatch *= nLines;

						dBatch -= dPreviousBatch;

						dBatch /= nLinesPerBatch;
					}

					InsertContent( dBatch, 3 );
					InsertContent( _T( "%" ) );

				EndColumn();

				BeginColumn();

				EndColumn();

				BeginColumn( haRight );

					InsertContent( a[ n ], 3 );
					InsertContent( _T( "%" ) );

				EndColumn();

			EndRow();

			nLines -= nLinesPerBatch;

			nRows++;

			if ( nRows == 100 )
			{
				break;
			}
		}

		if ( a.GetSize() == 0 )
		{
			BeginRow();

				BeginColumn( haRight );

					InsertContent( 0 );

				EndColumn();

				BeginColumn();

				EndColumn();

				BeginColumn( haRight );

					InsertContent( 0.0, 3 );
					InsertContent( _T( "%" ) );

				EndColumn();

				BeginColumn();

				EndColumn();

				BeginColumn( haRight );

					InsertContent( 0.0, 3 );
					InsertContent( _T( "%" ) );

				EndColumn();

			EndRow();
		}

		BeginRow();

			BeginColumn( 3, 5 );

			EndColumn();

		EndRow();

	EndTable();
}

LPCTSTR CDocumentPayoutHistoryWebPage::GetSubTitle() const
{
	return _T( "Payout History" );
}
